package com.javachmapi.springbootpoi.vo;


import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * 公共返回
 * create by 宋利军
 */
@ApiModel(value = "ResponseData", description = "通用返回")
public class ResponseData<T> {
    /**
     * 表示成功
     */
    public static final byte SUCCESS = 1;
    /**
     * 表示失败
     */
    public static final byte FAILURE = 0;

    @ApiModelProperty(value = "状态,0失败,1成功", dataType="byte")
    private byte state;
    @ApiModelProperty(value = "提示消息", dataType="byte")
    private String msg;

    @ApiModelProperty(value = "返回数据", dataType="byte")
    private T data;

    public ResponseData(byte state, String msg, T data) {
        this.state = state;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ResponseData<T> success() {
        return new ResponseData<>(SUCCESS, "", null);
    }

    public static <T> ResponseData<T> failure() {
        return new ResponseData<>(FAILURE, "", null);
    }

    public static <T> ResponseData<T> success(String msg) {
        return new ResponseData<>(SUCCESS, msg, null);
    }

    public static <T> ResponseData<T> failure(String msg) {
        return new ResponseData<>(FAILURE, msg, null);
    }

    public static <T> ResponseData<T> success(String msg, T data) {
        return new ResponseData<>(SUCCESS, msg, data);
    }

    public static <T> ResponseData<T> failure(String msg, T data) {
        return new ResponseData<>(FAILURE, msg, data);
    }

    public ResponseData msg(String msg) {
        this.msg = msg;
        return this;
    }

    public ResponseData data(T data) {
        this.data = data;
        return this;
    }
    public byte getState() {
        return state;
    }

    public void setState(byte state) {
        this.state = state;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}

